// 后台的菜单组织
window.menus = [
    {
        name: "基础信息",
        icon: "gear",
        left: [
            {
                name: "群列表",
                page: "group_list",
            },
        ]
    },
    {
        name: "群信息设置",
        icon: "gg",
        left: [
            {
                name: "基础信息",
                page: "base_setting",
            },
            {
                name: "群公告",
                page: "board",
            },
            {
                name: "成员列表",
                page: "members",
            },
        ],
    },
    {
        name: "财务管理",
        icon: "money",
        left: [
            {
                name: "余额变更",
                page: "balance_modify"
            },
            {
                name: "充值记录",
                page: "charge_log",
            },
            {
                name: "提款记录",
                page: "take_log",
            },
            {
                name: "扣款记录",
                page: "penalty_log",
            },
            {
                name: "抽水明细",
                page: "fee_log",
            },
            {
                name: "账变记录",
                page: "balance_log",
            },
        ],
    },
    {
        name: "报表管理",
        icon: "line-chart",
        left: [
            {
                name: "日盈亏总览",
                page: "win_lose_total",
            },
            {
                name: "月盈亏总览",
                page: "win_lose_month_total",
            },/*
            {
                name: "彩种盈亏",
                page: "win_lose_detail",
            },
            {
                name: "成员报表",
                page: "win_lose_detail",
            }, */
        ]
    },
    {
        name: "投注记录",
        icon: "list",
        left: [
            {
                name: "今日注单",
                page: "today",
            },
            {
                name: "历史注单",
                page: "bet_history",
            }
        ]
    },
    {
        name: "充值配置",
        icon: "cc-visa",
        left: [
            {
                name: "微信支付",
                page: "wechat",
            },
            {
                name: "财富通充值",
                page: "caifutong",
            },
            {
                name: "支付宝支付",
                page: "alipay",
            },
            {
                name: "银行支付配置",
                page: "bank",
            },
        ]
    },
    {
        name: "游戏管理",
        icon: "gamepad",
        left: [
            {
                name: "盘口设定",
                page: "lottery_setting",
            },
        ]
    },
    {
        name: "历史开奖",
        icon: "history",
        left: [
            {
                name: "北京PK10",
                page: "result/result_bjpk10",
            },
            {
                name: "重庆幸运农场",
                page: "result/result_cqkl10",
            },
            {
                name: "广东快乐十分",
                page: "result/result_gdkl10",
            },
            {
                name: "重庆时时彩",
                page: "result/result_cqssc",
            },
            {
                name: "新疆时时彩",
                page: "result/result_xjssc",
            },
            {
                name: "天津时时彩",
                page: "result/result_tjssc",
            },
            {
                name: "北京快乐8",
                page: "result/result_bjkl8",
            },
            {
                name: "江苏骰宝",
                page: "result/result_jsk3",
            },
            {
                name: "香港六合彩",
                page: "result/result_lhc",
            },
        ]
    },
];

function findMenu1(n) {
    for (var i in menus) {
        if (menus[i].name == n) return menus[i];
    }
}
function findMenu2(menu, n) {
    for (var i in menu.left) {
        if (menu.left[i].name == n) return menu.left[i];
    }
}

var ul = $(".left .left_menus");
ul.empty();
for (var i in menus) {
    if (window.bocai && menus[i].cp == true) continue;
    if (!window.bocai && menus[i].wx == true) continue;

    var li = $('<div class="item" value="' + menus[i].name + '"></div>');
    li.append('<a href="#" class="parent"><span class="am-icon-' + menus[i].icon + ' am-icon-sm"> ' + menus[i].name + '</span></a>');

    var submenus = $('<div class="submenus"></div>');
    for (var j in menus[i].left) {
        if (window.bocai && menus[i].left[j].cp == true) continue;
        if (!window.bocai && menus[i].left[j].wx == true) continue;

        var li2 = $('<a href="#" class="" value="' + menus[i].name + '">' + menus[i].left[j].name + '</a>');
        submenus.append(li2);
    }

    li.append(submenus);
    ul.append(li);
}

// 主菜单点击的处理
$(".left .item .parent").click(function(e) {
    var p = $(e.currentTarget).parent();
    if (p.attr("class").indexOf("active") != -1) {
        // 菜单缩起来
        p.attr("class", "item");
    }
    else {
        $(".left .item").attr("class", "item");
        p.attr("class", "item active");
    }
});

// 设置菜单选中
var n1 = urlInfo.params.n1 || menus[0].name;
var n2 = urlInfo.params.n2;
if (!n2) n2 = findMenu1(n1).left[0].name;
n1 = decodeURI(n1);
n2 = decodeURI(n2);
function updateMenus(n1, n2) {
    var arr = $(".left .item");
    for (var i = 0; i < arr.length; i++) {
        if ($(arr[i]).attr("value") == n1) {
            $(arr[i]).attr("class", "item active");

            var arr2 = $(arr[i]).find(".submenus a");
            for (var j = 0; j < arr2.length; j++) {
                if ($(arr2[j]).html() == n2) $(arr2[j]).attr("class", "active2");
                else $(arr2[j]).attr("class", "");
            }
        }
        else
            $(arr[i]).attr("class", "item");
    }
}
updateMenus(n1, n2);

// 菜单被点击的处理
$(".left .submenus a").click(function(e) {
    var t = $(e.currentTarget);
    var n1 = t.attr("value"),
        n2 = t.html();

    if (!e.ctrlKey) {
        PageHistory.load(n1, n2, 0);
    }
    else {
        var url = Util.genUrl({
            n1: n1,
            n2: n2,
            full_screen: 1,
        });
        window.open(url);
    }
});


// 填充顶部菜单
var ul = $("#top-menu");
ul.empty();
for (var i in menus) {
    ul.append("<a href='#'>" + menus[i].name + "</a>");
}
var arr = $("#top-menu a");
for (var i = 0; i < arr.length; i++) {
    $(arr[i]).click(function(e) {
        var n = $(e.currentTarget).html();
        var n1 = urlInfo.params.n1 || menus[0].name;
        n1 = decodeURI(n1);
        if (n == n1) return;

        Util.jumpUrl({
            n1: n,
            n2: "",
        });
    });
}

// 载入html文件
switch_page(findMenu2(findMenu1(n1), n2).page, $(".content .operation"));

// 设置导航路径
var ol = $(".am-breadcrumb");
ol.empty();
ol.append('<li><a href="#" class="am-icon-home">首页</a></li>');
ol.append('<li><a href="#">' + n1 + '</a></li>');
ol.append('<li><a href="#" class="am-active">' + n2 + '</a></li>');
